import React, { memo, useState,useEffect } from 'react'
import { Space, Table, Tag,Button } from 'antd';
import {getdraf} from '../../../api/home'
import Item from 'antd/es/list/Item';
import { useLocation } from "react-router-dom";
const check = memo(() => {
  const [current,setCurrent] = useState(1);
  const [pageSize, setPageSize] = useState(8);
  const [dataList,setDatalist] = useState([]);//列表数据
  let location = useLocation(); 
  console.log("params:",location);
 

  // 请求发布箱
  const getdrafs = ()=>{
    let info = JSON.parse(localStorage.params)
    let parmas = {
      category:info.category,
      page:info.page,
      pagesize:info.pagesize,
      searchKey:info.searchKey,
      state:location.state.state
    }
    console.log(parmas);
    getdraf(parmas).then(res =>{
      console.log(res);
      let data = res.data.result.data.map((item,i)=>{
      return{
        key:i,
        name:item.author,
        content:item.content,
        title:item.title,
        id:item.id,
        mainImage:item.mainImage
      }
      });
      console.log(data);
      setDatalist(data)
    })
  }

  // 博客编辑
  const goEdit = (index)=>{
    // navigate('/home/article/markown',{
    //   state:{
    //     info:dataList[index]
    //   }
    // })
  }

  useEffect(() => {
    getdrafs()
  },[])

  const columns = [
    {
      title: '名称',
      dataIndex: 'name',
      align:'center',
      key: 'name',
      render: (text) => <a>{text}</a>,
    },
    {
      title: '编辑内容',
      dataIndex: 'content',
      key: 'content',
      align:'center',
    },
    {
      title: '编辑标题',
      key: 'title',
      dataIndex: 'title',
      align:'center',
    },
    {
      title: '操作',
      key: 'action',
      dataIndex: 'action',
      align:'center'
    },
  ];

  return (
    <div style={{background:'#fff',borderRadius:'10px', padding:'10px',height:'100%'}}>
      <Table 
      bordered
      columns={columns} 
      dataSource={dataList} 
      pagination={{
        current,
        pageSize,
        total:dataList.length,
        showTotal(totla,range){
          return `共 ${totla} 条`
        },
        onChange(page,pageSize) {
          console.log(page,pageSize)
          setCurrent(page)
          setPageSize(pageSize)
        }
      }}/>
    </div>
  )
})

export default check
